﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CUiDisDisassemblyDynamicRootCmd
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EngineeringInternalExtension;
using System.Collections.ObjectModel;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands;

public class CUiDisDisassemblyDynamicRootCmd : TxButtonCommand
{
  private CApDisDisassemblyDynamicRootEnabler m_enabler;

  public CUiDisDisassemblyDynamicRootCmd()
  {
    this.m_enabler = new CApDisDisassemblyDynamicRootEnabler();
  }

  public virtual void Execute(object cmdParams)
  {
    if (!TxCommandLicenser.SetDynamicRootLicense)
    {
      TxMessageBoxEx.ShowNoLicenseError(base.Name);
    }
    else
    {
      Cursor current = Cursor.Current;
      try
      {
        Cursor.Current = Cursors.WaitCursor;
        if (!CApDisDisassemblyDynamicRootApp.IsCurrentSelectionValid())
          return;
        ITxObject selectedObj = ((Collection<ITxObject>) TxApplication.ActiveSelection.GetItems())[0];
        CApDisDisassemblyDynamicRootApp disassemblyDynamicRootApp = new CApDisDisassemblyDynamicRootApp();
        TxApplication.ActiveUndoManager.StartTransaction();
        disassemblyDynamicRootApp.SetDisassemblyDynamicRoot(selectedObj);
        TxApplication.ActiveUndoManager.EndTransaction();
        this.ResetSelection();
      }
      finally
      {
        Cursor.Current = current;
      }
    }
  }

  private void ResetSelection()
  {
    TxApplication.ActiveSelection.SetItems(TxApplication.ActiveSelection.GetAllItems());
  }

  public virtual string Category
  {
    get => this.GetResourceManager().GetString("SET_DISASSEMBLY_DYNAMIC_ROOT_CMD_CATEGORY");
  }

  public virtual string Name
  {
    get => this.GetResourceManager().GetString("SET_DISASSEMBLY_DYNAMIC_ROOT_CMD_NAME");
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.StringTable", ((object) this).GetType().Assembly);
  }

  public virtual string Bitmap
  {
    get => this.GetResourceManager().GetString("SET_DISASSEMBLY_DYNAMIC_ROOT_CMD_BITMAP");
  }

  public virtual string Description
  {
    get => this.GetResourceManager().GetString("SET_DISASSEMBLY_DYNAMIC_ROOT_CMD_DESCRIPTION");
  }

  public virtual string Tooltip
  {
    get => this.GetResourceManager().GetString("SET_DISASSEMBLY_DYNAMIC_ROOT_CMD_TOOLTIP");
  }

  public virtual ITxCommandEnabler CommandEnabler => (ITxCommandEnabler) this.m_enabler;

  public virtual bool Connect() => true;
}
